//#include <base.js>
//#include <openlayersExt.js>
//#include <event.js>


/**
* 
* Factory per creazione di widget 
* 
* @namespace CWN2
* @class widgetFactory
* 
*/

CWN2.widgetFactory = {

	/**
	* 
	* Create an widget
	* 
	* @method create
	* 
	* @param {widgetConfig} widgetConfig Obj containing the widget configuration 
	* 
	* @return: 	{OpenLayers.Layer}
	* 
	*/ 
	
	create: function(widgetConfig) {

		if (CWN2.base.DEBUG) {
			console.log('CWN2.widgetFactory.create');
		}
		return CWN2.widgetFactory[widgetConfig.name](widgetConfig);
	
	},
	
	
	CoordinateReadOut: function(widgetConfig) {

		if (CWN2.base.DEBUG) {
			console.log('CWN2.widgetFactory.CoordinateReadOut');
		}
		
		var cbFunction = function(e) {
			
			var lonLat = this.getLonLatFromPixel(e.xy);
			
			// TODO: gestione conversione coordinate da 900913 a GB / WGS84
			//if (CWN2.base.map.displayProjection) {
			//	lonLat.transform(CWN2.base.map.getProjectionObject(),
			//			CWN2.base.map.displayProjection);
			//} 
		
			//Ext.getCmp("x-coord").setText("X: " + lonLat.lon.toFixed(0));
			//Ext.getCmp("y-coord").setText("Y: " + lonLat.lat.toFixed(0));
			Ext.getCmp("coordinate-readout").setText("Coordinate: X=" + lonLat.lon.toFixed(0) + " Y=" + lonLat.lat.toFixed(0));

		}
		
		// registro l'evento sul mousemove (scrittura coodinate su statusbar)
		CWN2.base.map.events.register("mousemove", CWN2.base.map, cbFunction);


		return null;
	
	}


};
